package com.bjpowernode.boss.mvc.controller;

import com.bjpowernode.boss.mvc.models.AjaxResult;
import com.bjpowernode.boss.mvc.models.dto.operator.LoginResponseDto;
import com.bjpowernode.boss.mvc.models.form.operator.LoginForm;
import com.bjpowernode.boss.mvc.models.menus.SubMenu;
import com.bjpowernode.boss.mvc.service.OperatorService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/operator")
public class OperatorController {


    @Resource
    private OperatorService operatorService;

    /*登录，获取token*/
    @PostMapping("/login")
    public AjaxResult operatorLogin(@RequestBody @Validated LoginForm loginForm){
        //进行登录，生成jwt
        LoginResponseDto loginResponseDto = operatorService.operatorLogin(loginForm);
        //返回dto给前端
        return AjaxResult.ok(loginResponseDto);
    }
    /*根据登录用户获取菜单列表*/
    @GetMapping("/menus")
    public AjaxResult getMenus(@RequestHeader("operatorId") Long operatorId){
        //调用service获取菜单
        List<SubMenu> subMenuList = operatorService.getMenusByLoginUser(operatorId);
        return  AjaxResult.ok(subMenuList);
    }
}
